import { goodsType } from "../../api";
const MUTATION_TYPES = {
  GOODS_TYPE_LIST: "GOODS_TYPE_LIST",
  GOODS_TYPE_SIZE: "GOODS_TYPE_SIZE"
};

const state = {
  goodsTypeList: [],
  totalGoodsTypeSize: 0
};
const getters = {};

const mutations = {
  [MUTATION_TYPES.GOODS_TYPE_LIST](state, goodsTypeList) {
    state.goodsTypeList = goodsTypeList;
  },
  [MUTATION_TYPES.GOODS_TYPE_SIZE](state, totalGoodsTypeSize) {
    state.totalGoodsTypeSize = totalGoodsTypeSize;
  }
};

const actions = {
  async search({ commit }, filter = {}) {
    let response = await goodsType.search(filter);
    if (response?.code === 0) {
      commit(MUTATION_TYPES.GOODS_TYPE_LIST, response.data?.records);
      commit(MUTATION_TYPES.GOODS_TYPE_SIZE, response.data?.total);
    }
  }
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
};
